home *** CD-ROM | disk | FTP | other *** search
/ LG Super CD / LG Super CD.iso / bitpim / bitpim-0.62-setup.exe / {app} / bitpim.exe / linecache.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-11-06  |  2.4 KB  |  97 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.3)
  3.  
  4. import sys
  5. import os
  6. __all__ = [
  7.     'getline',
  8.     'clearcache',
  9.     'checkcache']
  10.  
  11. def getline(filename, lineno):
  12.     lines = getlines(filename)
  13.     if lineno <= lineno:
  14.         pass
  15.     elif lineno <= len(lines):
  16.         return lines[lineno - 1]
  17.     else:
  18.         return ''
  19.  
  20. cache = { }
  21.  
  22. def clearcache():
  23.     global cache
  24.     cache = { }
  25.  
  26.  
  27. def getlines(filename):
  28.     if filename in cache:
  29.         return cache[filename][2]
  30.     else:
  31.         return updatecache(filename)
  32.  
  33.  
  34. def checkcache():
  35.     for filename in cache.keys():
  36.         (size, mtime, lines, fullname) = cache[filename]
  37.         
  38.         try:
  39.             stat = os.stat(fullname)
  40.         except os.error:
  41.             del cache[filename]
  42.             continue
  43.  
  44.         if size != stat.st_size or mtime != stat.st_mtime:
  45.             del cache[filename]
  46.             continue
  47.     
  48.  
  49.  
  50. def updatecache(filename):
  51.     if filename in cache:
  52.         del cache[filename]
  53.     
  54.     if not filename or filename[0] + filename[-1] == '<>':
  55.         return []
  56.     
  57.     fullname = filename
  58.     
  59.     try:
  60.         stat = os.stat(fullname)
  61.     except os.error:
  62.         msg = None
  63.         basename = os.path.split(filename)[1]
  64.         for dirname in sys.path:
  65.             
  66.             try:
  67.                 fullname = os.path.join(dirname, basename)
  68.             except (TypeError, AttributeError):
  69.                 continue
  70.  
  71.             
  72.             try:
  73.                 stat = os.stat(fullname)
  74.             continue
  75.             except os.error:
  76.                 continue
  77.             
  78.  
  79.         else:
  80.             return []
  81.     except:
  82.         None<EXCEPTION MATCH>os.error
  83.  
  84.     
  85.     try:
  86.         fp = open(fullname, 'rU')
  87.         lines = fp.readlines()
  88.         fp.close()
  89.     except IOError:
  90.         msg = None
  91.         return []
  92.  
  93.     (size, mtime) = (stat.st_size, stat.st_mtime)
  94.     cache[filename] = (size, mtime, lines, fullname)
  95.     return lines
  96.  
  97.